<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<div class="setp_top">
	<div class="setp_top_btn">
		&nbsp;<s:if test="#request.isCreate == 1">
			<input type="button" class="btn_ok" onclick="nextStep()" />
		</s:if>
		<input type="button" class="btn_cancel" onclick="prevStep()" />
	</div>
	<s:property value="#typeTxt"/>&nbsp;<s:property value="#workStatusTxt"/>
</div>
<div class="setp_main">
	<div class="fee_border" style="border:0; margin-top: -15px; text-align:right; font-size: 12px;">
		显示币种：
		<select class="special" id="maincurrency" name="maincurrency" onchange="changeMainCurrency()">
			<s:iterator value="%{#request.currencys}">
				<option value="<s:property value="id"/>"><s:property value="type"/></option>
			</s:iterator>
		</select>
	</div>
	
	<input type="hidden" id="feeSum" name="feeSum"/>
	<s:set var="feeSum" value="0"></s:set>
	
	<!-- 应收款 -->
	<div class="fee_border" style="margin-top: 0;">
		<div class="fee_add_div"><a href="javascript: addFees(1)" class="fee_add">添加应收款</a></div>
		<span class="fee_place" style="color:#5069C6">+&nbsp;应收款<span style="font-size: 14px;">(合计)</span>：<span id="span_count_1"></span>&nbsp;<span id="span_count_2"></span></span>
		<table id="feeTable1" class="tab1" cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 10px;">
			<thead>
				<tr>
					<td width="75px"><span class="stress">*</span>付款方</td>
					<td width="75px"><span class="stress">*</span>费用名称</td>
					<td width="55px"><span class="stress">*</span>货币</td>
					<td width="40px"><span class="stress">*</span>数量</td>
					<td width="60px"><span class="stress">*</span>单价</td>
					<td width="70px" class="stress_bg">应收金额</td>
					<td width="80px">代收方</td>
					<td width="70px" class="stress_bg">已结算金额</td>
					<td>说明</td>
					<td width="50px">&nbsp;</td>
				</tr>
			</thead>
			<s:iterator value="%{#request.workFees1}" status="sta">
				<s:set var="feeSum" value="#feeSum + 1"></s:set>
				<tr class="<s:if test="#sta.isEven()">tr1</s:if>" id="feeTr_<s:property value="#feeSum"/>">
					<td>
						<span>
							<s:property value="employee1.nickname"/>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="employee1.nickname"/>" id="employee1_<s:property value="#feeSum"/>" name="employee1_<s:property value="#feeSum"/>" 
								onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=1',this.value,'employee1_<s:property value="#feeSum"/>','employee1Id_<s:property value="#feeSum"/>',0,200);" class="input_normal"/>
							<input type="hidden" value="<s:property value="employee1.id"/>" id="employee1Id_<s:property value="#feeSum"/>" name="employee1Id_<s:property value="#feeSum"/>"/>
							<input type="hidden" value="<s:property value="id"/>" id="workFeeId_<s:property value="#feeSum"/>" name="workFeeId_<s:property value="#feeSum"/>"/>
							<input type="hidden" id="type_<s:property value="#feeSum"/>" name="type_<s:property value="#feeSum"/>" value="0"/>
							<input type="hidden" value="<s:property value="money"/>" id="money_<s:property value="#feeSum"/>" name="money_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td>
						<span>
							<s:property value="fee.name_zh"/>
						</span>
						<span style="display: none">
							<select class="select_normal" id="fees_<s:property value="#feeSum"/>" name="fees_<s:property value="#feeSum"/>">
								<option value="0">-请选择-</option>
								<s:iterator value="%{#request.fees}">
									<option value="<s:property value="id"/>" <s:if test="fee.id==id">selected</s:if>><s:property value="name"/></option>
								</s:iterator>
							</select>
						</span>
					</td>
					<td>
						<span>
							<s:property value="currency.type"/>
						</span>
						<span style="display: none">
							<select class="select_normal" id="currency_<s:property value="#feeSum"/>" name="currency_<s:property value="#feeSum"/>">
								<option value="0">请选择</option>
								<s:iterator value="%{#request.currencys}">
									<option value="<s:property value="id"/>" <s:if test="currency.id==id">selected</s:if>><s:property value="type"/></option>
								</s:iterator>
							</select>
						</span>
					</td>
					<td>
						<span>
							<s:property value="quantity"/>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="quantity"/>" id="quantity_<s:property value="#feeSum"/>" name="quantity_<s:property value="#feeSum"/>" class="input_normal" value="1"/>
						</span>
					</td>
					<td>
						<span>
							<s:property value="unitPrice"/>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="unitPrice"/>" id="unitPrice_<s:property value="#feeSum"/>" name="unitPrice_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td class="stress_bg">
						<s:property value="money"/>
					</td>
					<td>
						<span>
							<s:property value="employee2.nickname"/>&nbsp;
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="employee2.nickname"/>" id="employee2_<s:property value="#feeSum"/>" name="employee2_<s:property value="#feeSum"/>" 
								onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=1',this.value,'employee2_<s:property value="#feeSum"/>','employee2Id_<s:property value="#feeSum"/>',0,200);" class="input_normal"/>
							<input type="hidden" value="<s:property value="employee2.id"/>" id="employee2Id_<s:property value="#feeSum"/>" name="employee2Id_<s:property value="#feeSum"/>"/>
						</span>
					</td>
					<td class="stress_bg">
						<s:property value="writtenOffmoney != 0 ? writtenOffmoney : null"/>&nbsp;
					</td>
					<td title="<s:property value="remark"/>">
						<span>
							<div class="nowrap" style="width: 100px">
								<s:property value="remark"/>&nbsp;
							</div>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="remark"/>" id="remark_<s:property value="#feeSum"/>" name="remark_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td>
						<span>
							<a id="a_fee_edit_<s:property value="#feeSum"/>" class="fee_edit" href="javascript: toEditFeesStyle('<s:property value="#feeSum"/>', 1)"></a>
						</span>
						<span style="display: none">
							<a id="a_fee_ok_<s:property value="#feeSum"/>" class="fee_ok" href="javascript: saveFees('<s:property value="#feeSum"/>', 1)"></a>
						</span>
						<a class="fee_del" href="javascript: deleteFees('<s:property value="#feeSum"/>', 1)"></a>
					</td>
				</tr>
			</s:iterator>
			<s:set var="feeSum" value="#feeSum + 1"></s:set>
			<tr id="feeTr_<s:property value="#feeSum"/>" style="display: none;">
				<td>
					<span style="display: none;"></span>
					<span>
						<input type="text" id="employee1_<s:property value="#feeSum"/>" name="employee1_<s:property value="#feeSum"/>" class="input_normal"/>
						<input type="hidden" id="employee1Id_<s:property value="#feeSum"/>" name="employee1Id_<s:property value="#feeSum"/>"/>
						<input type="hidden" id="workFeeId_<s:property value="#feeSum"/>" name="workFeeId_<s:property value="#feeSum"/>"/>
						<input type="hidden" id="type_<s:property value="#feeSum"/>" name="type_<s:property value="#feeSum"/>" value="0"/>
						<input type="hidden" id="money_<s:property value="#feeSum"/>" name="money_<s:property value="#feeSum"/>" class="input_normal"/>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<select class="select_normal" id="fees_<s:property value="#feeSum"/>" name="fees_<s:property value="#feeSum"/>">
							<option value="0">-请选择-</option>
							<s:iterator value="%{#request.fees}">
								<option value="<s:property value="id"/>"><s:property value="name"/></option>
							</s:iterator>
						</select>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<select class="select_normal" id="currency_<s:property value="#feeSum"/>" name="currency_<s:property value="#feeSum"/>">
							<option value="0">请选择</option>
							<s:iterator value="%{#request.currencys}">
								<option value="<s:property value="id"/>"><s:property value="type"/></option>
							</s:iterator>
						</select>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<input type="text" id="quantity_<s:property value="#feeSum"/>" name="quantity_<s:property value="#feeSum"/>" class="input_normal" value="1"/>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<input type="text" id="unitPrice_<s:property value="#feeSum"/>" name="unitPrice_<s:property value="#feeSum"/>" class="input_normal"/>
					</span>
				</td>
				<td class="stress_bg">&nbsp;
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<input type="text" id="employee2_<s:property value="#feeSum"/>" name="employee2_<s:property value="#feeSum"/>" class="input_normal"/>
						<input type="hidden" id="employee2Id_<s:property value="#feeSum"/>" name="employee2Id_<s:property value="#feeSum"/>"/>
					</span>
				</td>
				<td class="stress_bg">&nbsp;</td>
				<td class="nowrap">
					<span style="display: none">
						<div class="nowrap" style="width: 100px">
						</div>
					</span>
					<span>
						<input type="text" id="remark_<s:property value="#feeSum"/>" name="remark_<s:property value="#feeSum"/>" class="input_normal"/>
					</span>
				</td>
				<td>
					<span style="display: none">
						<a id="a_fee_edit_<s:property value="#feeSum"/>" class="fee_edit"></a>
					</span>
					<span>
						<a id="a_fee_ok_<s:property value="#feeSum"/>" class="fee_ok"></a>
					</span>
					<a id="a_fee_del_<s:property value="#feeSum"/>" href="javascript:" class="fee_del"></a>
				</td>
			</tr>
		</table>
	</div>
	
	<!-- 应付款 -->
	<div class="fee_border">
		<div class="fee_add_div"><a href="javascript: addFees(2)" class="fee_add">添加应付款</a></div>
		<span class="fee_place" style="color:#F45917">-&nbsp;应付款<span style="font-size: 14px;">(合计)</span>：<span id="span_count_3"></span>&nbsp;<span id="span_count_4"></span></span>
		<table id="feeTable2" class="tab1" cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 10px;">
			<thead>
				<tr>
					<td width="75px"><span class="stress">*</span>收款方</td>
					<td width="75px"><span class="stress">*</span>费用名称</td>
					<td width="55px"><span class="stress">*</span>货币</td>
					<td width="40px"><span class="stress">*</span>数量</td>
					<td width="60px"><span class="stress">*</span>单价</td>
					<td width="70px" class="stress_bg">应付金额</td>
					<td width="80px">代付方</td>
					<td width="70px" class="stress_bg">已结算金额</td>
					<td>说明</td>
					<td width="50px">&nbsp;</td>
				</tr>
			</thead>
			<s:iterator value="%{#request.workFees2}" status="sta">
				<s:set var="feeSum" value="#feeSum + 1"></s:set>
				<tr class="<s:if test="#sta.isEven()">tr1</s:if>" id="feeTr_<s:property value="#feeSum"/>">
					<td>
						<span>
							<s:property value="employee1.nickname"/>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="employee1.nickname"/>" id="employee1_<s:property value="#feeSum"/>" name="employee1_<s:property value="#feeSum"/>" 
								onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=1',this.value,'employee1_<s:property value="#feeSum"/>','employee1Id_<s:property value="#feeSum"/>',0,200);" class="input_normal"/>
							<input type="hidden" value="<s:property value="employee1.id"/>" id="employee1Id_<s:property value="#feeSum"/>" name="employee1Id_<s:property value="#feeSum"/>"/>
							<input type="hidden" value="<s:property value="id"/>" id="workFeeId_<s:property value="#feeSum"/>" name="workFeeId_<s:property value="#feeSum"/>"/>
							<input type="hidden" id="type_<s:property value="#feeSum"/>" name="type_<s:property value="#feeSum"/>" value="1"/>
							<input type="hidden" id="workItemId_<s:property value="#feeSum"/>" name="workItemId_<s:property value="#feeSum"/>" 
								value="<s:if test="workItem == null">0</s:if><s:else><s:property value="workItem.id"/></s:else>"/>
							<input type="hidden" value="<s:property value="money"/>" id="money_<s:property value="#feeSum"/>" name="money_<s:property value="#feeSum"/>"/>
						</span>
					</td>
					<td>
						<span>
							<s:property value="fee.name_zh"/>
						</span>
						<span style="display: none">
							<select class="select_normal" id="fees_<s:property value="#feeSum"/>" name="fees_<s:property value="#feeSum"/>" srcValue="<s:property value="fee.id"/>" <s:if test="fee.item != null">srcHasItem="1"</s:if><s:else>srcHasItem=""</s:else>>
								<option value="0">-请选择-</option>
								<s:iterator value="%{#request.fees}">
									<option <s:if test="item != null">hasItem="1"</s:if><s:else>hasItem=""</s:else> value="<s:property value="id"/>" <s:if test="fee.id==id">selected</s:if>><s:property value="name"/></option>
								</s:iterator>
							</select>
						</span>
					</td>
					<td>
						<span>
							<s:property value="currency.type"/>
						</span>
						<span style="display: none">
							<select class="select_normal" id="currency_<s:property value="#feeSum"/>" name="currency_<s:property value="#feeSum"/>">
								<option value="0">请选择</option>
								<s:iterator value="%{#request.currencys}">
									<option value="<s:property value="id"/>" <s:if test="currency.id==id">selected</s:if>><s:property value="type"/></option>
								</s:iterator>
							</select>
						</span>
					</td>
					<td>
						<span>
							<s:property value="quantity"/>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="quantity"/>" id="quantity_<s:property value="#feeSum"/>" name="quantity_<s:property value="#feeSum"/>" class="input_normal" value="1"/>
						</span>
					</td>
					<td>
						<span>
							<s:property value="unitPrice"/>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="unitPrice"/>" id="unitPrice_<s:property value="#feeSum"/>" name="unitPrice_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td class="stress_bg">
						<s:property value="money"/>
					</td>
					<td>
						<span>
							<s:property value="employee2.nickname"/>&nbsp;
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="employee2.nickname"/>" id="employee2_<s:property value="#feeSum"/>" name="employee2_<s:property value="#feeSum"/>" 
								onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=1',this.value,'employee2_<s:property value="#feeSum"/>','employee2Id_<s:property value="#feeSum"/>',0,200);" class="input_normal"/>
							<input type="hidden" value="<s:property value="employee2.id"/>" id="employee2Id_<s:property value="#feeSum"/>" name="employee2Id_<s:property value="#feeSum"/>"/>
						</span>
					</td>
					<td class="stress_bg">
						<s:property value="writtenOffmoney != 0 ? writtenOffmoney : null"/>&nbsp;
					</td>
					<td title="<s:property value="remark"/>">
						<span>
							<div class="nowrap" style="width: 100px">
								<s:property value="remark"/>&nbsp;
							</div>
						</span>
						<span style="display: none">
							<input type="text" value="<s:property value="remark"/>" id="remark_<s:property value="#feeSum"/>" name="remark_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td>
						<span>
							<a id="a_fee_edit_<s:property value="#feeSum"/>" class="fee_edit" href="javascript: toEditFeesStyle('<s:property value="#feeSum"/>', 2)"></a>
						</span>
						<span style="display: none">
							<a id="a_fee_ok_<s:property value="#feeSum"/>" class="fee_ok" href="javascript: saveFees('<s:property value="#feeSum"/>', 2)"></a>
						</span>
						<a class="fee_del" href="javascript: deleteFees('<s:property value="#feeSum"/>', 2)"></a>
					</td>
				</tr>
			</s:iterator>
			<s:set var="feeSum" value="#feeSum + 1"></s:set>
			<tr id="feeTr_<s:property value="#feeSum"/>" style="display: none;">
				<td>
					<span style="display: none"></span>
					<span>
						<input type="text" id="employee1_<s:property value="#feeSum"/>" name="employee1_<s:property value="#feeSum"/>" class="input_normal"/>
						<input type="hidden" id="employee1Id_<s:property value="#feeSum"/>" name="employee1Id_<s:property value="#feeSum"/>"/>
						<input type="hidden" id="workFeeId_<s:property value="#feeSum"/>" name="workFeeId_<s:property value="#feeSum"/>"/>
						<input type="hidden" id="workItemId_<s:property value="#feeSum"/>" name="workItemId_<s:property value="#feeSum"/>"/>
						<input type="hidden" id="type_<s:property value="#feeSum"/>" name="type_<s:property value="#feeSum"/>" value="1"/>
						<input type="hidden" id="money_<s:property value="#feeSum"/>" name="money_<s:property value="#feeSum"/>" class="input_normal"/>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<select class="select_normal" id="fees_<s:property value="#feeSum"/>" name="fees_<s:property value="#feeSum"/>" srcValue="" <s:if test="fee.item != null">srcHasItem="1"</s:if><s:else>srcHasItem=""</s:else>>
							<option value="0">-请选择-</option>
							<s:iterator value="%{#request.fees}">
								<option <s:if test="item != null">hasItem="1"</s:if><s:else>hasItem=""</s:else> value="<s:property value="id"/>"><s:property value="name"/></option>
							</s:iterator>
						</select>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<select class="select_normal" id="currency_<s:property value="#feeSum"/>" name="currency_<s:property value="#feeSum"/>">
							<option value="0">请选择</option>
							<s:iterator value="%{#request.currencys}">
								<option value="<s:property value="id"/>"><s:property value="type"/></option>
							</s:iterator>
						</select>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<input type="text" id="quantity_<s:property value="#feeSum"/>" name="quantity_<s:property value="#feeSum"/>" class="input_normal" value="1"/>
					</span>
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<input type="text" id="unitPrice_<s:property value="#feeSum"/>" name="unitPrice_<s:property value="#feeSum"/>" class="input_normal"/>
					</span>
				</td>
				<td class="stress_bg">&nbsp;
				</td>
				<td>
					<span style="display: none"></span>
					<span>
						<input type="text" id="employee2_<s:property value="#feeSum"/>" name="employee2_<s:property value="#feeSum"/>" class="input_normal"/>
						<input type="hidden" id="employee2Id_<s:property value="#feeSum"/>" name="employee2Id_<s:property value="#feeSum"/>"/>
					</span>
				</td>
				<td class="stress_bg">&nbsp;</td>
				<td class="nowrap">
					<span style="display: none">
						<div class="nowrap" style="width: 100px">
						</div>
					</span>
					<span>
						<input type="text" id="remark_<s:property value="#feeSum"/>" name="remark_<s:property value="#feeSum"/>" class="input_normal"/>
					</span>
				</td>
				<td>
					<span style="display: none">
						<a id="a_fee_edit_<s:property value="#feeSum"/>" class="fee_edit"></a>
					</span>
					<span>
						<a id="a_fee_ok_<s:property value="#feeSum"/>" class="fee_ok"></a>
					</span>
					<a id="a_fee_del_<s:property value="#feeSum"/>" href="javascript:" class="fee_del"></a>
				</td>
			</tr>
		</table>
	</div>
	
	<s:if test="#request.employee.auth2 == 1">
		<!-- 奖励 -->
		<div class="fee_border">
			<div class="fee_add_div"><a href="javascript: addFees(3)" class="fee_add">添加奖励款</a></div>
			<span class="fee_place" style="color:#8F680B">-&nbsp;奖励<span style="font-size: 14px;">(合计)</span>：<span id="span_count_5"></span>&nbsp;<span id="span_count_6"></span></span>
			<table id="feeTable3" class="tab1" cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 10px;">
				<thead>
					<tr>
						<td width="90px"><span class="stress">*</span>被奖励人</td>
						<td width="55px"><span class="stress">*</span>货币</td>
						<td width="75px">A定额奖金</td>
						<td width="75px">B比例奖金(%)</td>
						<td width="80px" class="stress_bg">A+B奖励金额</td>
						<td width="80px" class="stress_bg">结算时间</td>
						<td>说明</td>
						<td width="50px">&nbsp;</td>
					</tr>
				</thead>
				<s:iterator value="%{#request.workFees3}" status="sta">
					<s:set var="feeSum" value="#feeSum + 1"></s:set>
					<tr class="<s:if test="#sta.isEven()">tr1</s:if>" id="feeTr_<s:property value="#feeSum"/>">
						<td>
							<span>
								<s:property value="employee1.nickname"/>
							</span>
							<span style="display: none">
								<input type="text" value="<s:property value="employee1.nickname"/>" id="employee1_<s:property value="#feeSum"/>" name="employee1_<s:property value="#feeSum"/>" 
									onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=all',this.value,'employee1_<s:property value="#feeSum"/>','employee1Id_<s:property value="#feeSum"/>',0,200);" class="input_normal"/>
								<input type="hidden" value="<s:property value="employee1.id"/>" id="employee1Id_<s:property value="#feeSum"/>" name="employee1Id_<s:property value="#feeSum"/>"/>
								<input type="hidden" value="<s:property value="id"/>" id="workFeeId_<s:property value="#feeSum"/>" name="workFeeId_<s:property value="#feeSum"/>"/>
								<input type="hidden" id="type_<s:property value="#feeSum"/>" name="type_<s:property value="#feeSum"/>" value="2"/>
							</span>
						</td>
						<td>
							<span>
								<s:property value="currency.type"/>
							</span>
							<span style="display: none">
								<select class="select_normal" id="currency_<s:property value="#feeSum"/>" name="currency_<s:property value="#feeSum"/>">
									<option value="0">请选择</option>
									<s:iterator value="%{#request.currencys}">
										<option value="<s:property value="id"/>" <s:if test="currency.id==id">selected</s:if>><s:property value="type"/></option>
									</s:iterator>
								</select>
							</span>
						</td>
						<td>
							<span>
								<s:property value="quotaReward"/>
							</span>
							<span style="display: none">
								<input type="text" value="<s:property value="quotaReward"/>" id="quotaReward_<s:property value="#feeSum"/>" name="quotaReward_<s:property value="#feeSum"/>" class="input_normal" value="1"/>
							</span>
							&nbsp;
						</td>
						<td>
							<span>
								<s:if test="ratioReward != null">
									<s:property value="ratioReward"/>%
								</s:if>
							</span>
							<span style="display: none">
								<input type="text" value="<s:if test="ratioReward != null"><s:property value="ratioReward"/>%</s:if>" id="ratioReward_<s:property value="#feeSum"/>" name="ratioReward_<s:property value="#feeSum"/>" class="input_normal"/>
							</span>
							&nbsp;
						</td>
						<td class="stress_bg">
							<s:property value="totalReward"/>
						</td>
						<td class="stress_bg">
							<s:date name="rewardTime" format="yyyy-MM-dd"/>&nbsp;
						</td>
						<td title="<s:property value="remark"/>">
							<span>
								<div class="nowrap" style="width: 150px">
									<s:property value="remark"/>&nbsp;
								</div>
							</span>
							<span style="display: none">
								<input type="text" value="<s:property value="remark"/>" id="remark_<s:property value="#feeSum"/>" name="remark_<s:property value="#feeSum"/>" class="input_normal"/>
							</span>
						</td>
						<td>
							<span>
								<a id="a_fee_edit_<s:property value="#feeSum"/>" class="fee_edit" href="javascript: toEditFeesStyle('<s:property value="#feeSum"/>', 3)"></a>
							</span>
							<span style="display: none">
								<a id="a_fee_ok_<s:property value="#feeSum"/>" class="fee_ok" href="javascript: saveFees('<s:property value="#feeSum"/>', 3)"></a>
							</span>
							<a class="fee_del" href="javascript: deleteFees('<s:property value="#feeSum"/>', 3)"></a>
						</td>
					</tr>
				</s:iterator>
				<s:set var="feeSum" value="#feeSum + 1"></s:set>
				<tr id="feeTr_<s:property value="#feeSum"/>" style="display: none;">
					<td>
						<span style="display: none"></span>
						<span>
							<input type="text" id="employee1_<s:property value="#feeSum"/>" name="employee1_<s:property value="#feeSum"/>" class="input_normal"/>
							<input type="hidden" id="employee1Id_<s:property value="#feeSum"/>" name="employee1Id_<s:property value="#feeSum"/>"/>
							<input type="hidden" id="workFeeId_<s:property value="#feeSum"/>" name="workFeeId_<s:property value="#feeSum"/>"/>
							<input type="hidden" id="type_<s:property value="#feeSum"/>" name="type_<s:property value="#feeSum"/>" value="2"/>
						</span>
					</td>
					<td>
						<span style="display: none"></span>
						<span>
							<select class="select_normal" id="currency_<s:property value="#feeSum"/>" name="currency_<s:property value="#feeSum"/>">
								<option value="0">请选择</option>
								<s:iterator value="%{#request.currencys}">
									<option value="<s:property value="id"/>"><s:property value="type"/></option>
								</s:iterator>
							</select>
						</span>
					</td>
					<td>
						<span style="display: none"></span>
						<span>
							<input type="text" id="quotaReward_<s:property value="#feeSum"/>" name="quotaReward_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td>
						<span style="display: none"></span>
						<span>
							<input type="text" id="ratioReward_<s:property value="#feeSum"/>" name="ratioReward_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td class="stress_bg">&nbsp;
					</td>
					<td class="stress_bg">&nbsp;</td>
					<td class="nowrap">
						<span style="display: none">
							<div class="nowrap" style="width: 150px">
							</div>
						</span>
						<span>
							<input type="text" id="remark_<s:property value="#feeSum"/>" name="remark_<s:property value="#feeSum"/>" class="input_normal"/>
						</span>
					</td>
					<td>
						<span style="display: none">
							<a id="a_fee_edit_<s:property value="#feeSum"/>" class="fee_edit"></a>
						</span>
						<span>
							<a id="a_fee_ok_<s:property value="#feeSum"/>" class="fee_ok"></a>
						</span>
						<a id="a_fee_del_<s:property value="#feeSum"/>" href="javascript:" class="fee_del"></a>
					</td>
				</tr>
			</table>
		</div>
	</s:if>
</div>

<div id="fee_items_div" class="popdiv_inner" style="width: 750px;">
	<div class="popdiv_inner_outter"></div>
	<div class="popdiv_close"></div>
	<div class="popdiv_handle" title="鼠标左键按住可拖动"></div>
	<div class="popdiv_content"></div>
</div>

<script type="text/javascript">
	var feeOpFlag = 0; //操作控制
	var feeSum = '<s:property value="#feeSum" />';
	var patrnNumber = /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,4})?$/;
	var workId = '<s:property value="work.id"/>';
	var currencyArrs;
	var auth2 = '<s:property value="#request.employee.auth2"/>';
	
	$(function(){
		var allCurrencyToRMB = '<s:property value="#request.allCurrencyToRMB"/>';
		currencyArrs = new Array();
		if(allCurrencyToRMB != ''){
			var arrs = allCurrencyToRMB.split(';');
			for(var i=0; i<arrs.length; i++){
				currencyArrs[arrs[i].split(',')[0]] = arrs[i].split(',')[1];
			}
		}
		changeMainCurrency();
		
		var rewardVerifyStatus = '<s:property value="work.rewardVerifyStatus"/>';
		var isSettled = false;
		$('#feeTable3 tr:gt(0):visible').find('td:eq(5)').each(function(){
			if($.trim($(this).text()) != ''){
				isSettled = true;
				$(this).parent().find('td:last a').hide();
			}
		})
		if(rewardVerifyStatus != 1 || isSettled){
			$('div.fee_add_div').not(':last').hide();
			$('#feeTable1,#feeTable2').find('tr').find('td:last a').hide();
		}else{
			$('#feeTable1,#feeTable2').find('tr:gt(0):visible').find('td:eq(7)').each(function(){
				if($.trim($(this).text()) != ''){
					$(this).parent().find('td:last a').hide();
				}
			})
		}
	})
	
	function changeMainCurrency(){
		if(feeOpFlag == 1){
			alert('请先完成正在操作中的费用！');
			$('#maincurrency option').each(function(){
				if($(this).text() == $('#span_count_1').text()){
					$(this).attr('selected', true);
				}
			})
			
			return false;
		}
		countFees(1);
		countFees(2);
	}
	
	//新加费用
	function addFees(tabindex){
		if(feeOpFlag == 1){
			alert('请先完成正在操作中的费用！');
			return;
		}
		feeSum++;
		var table = $("#feeTable" + tabindex);
		var templateTr = table.find("tr:hidden");
		var copyTr = templateTr.clone();
		copyTr.show();
		$(copyTr).attr('id', 'feeTr_' + feeSum);
		$(copyTr).find("input,select,a").each(function(){
			var id = this.id;
			if(id && id != ''){
				var idpart1 = id.substring(0, id.lastIndexOf('_') + 1);
				this.id = idpart1 + feeSum;
				this.name = idpart1 + feeSum;
			}
		});
		var theas = $(copyTr).find("td:last a");
		
		theas.eq(0).attr('href', 'javascript: toEditFeesStyle('+feeSum+', '+tabindex+')');
		theas.eq(1).attr('href', 'javascript: saveFees('+feeSum+', '+tabindex+')');
		theas.eq(2).attr('href', 'javascript: deleteFees('+feeSum+', '+tabindex+')');
		var employType = 1;
		if(tabindex == 3){
			employType = 'all';
		}
		$(copyTr).find("input[id*=employee1_]").each(function(){
			$(this).keyup(function(e){
				seachDataByKeyword('searchEmployeeBykeyword.action?type=' + employType,this.value,'employee1_' + feeSum,'employee1Id_' + feeSum,0,200);
			})
		});
		$(copyTr).find("input[id*=employee2_]").each(function(){
			$(this).keyup(function(e){
				seachDataByKeyword('searchEmployeeBykeyword.action?type=' + employType,this.value,'employee2_' + feeSum,'employee2Id_' + feeSum,0,200);
			})
		});
		copyTr.find('td').not(':last').css('padding', '0px')
		if(tabindex == 1 || tabindex == 2){
			copyTr.find("input[id*=quantity],input[id*=unitPrice]").blur(function(){
				var thid = $(this).attr('id');
				var index = thid.substring(thid.indexOf('_') + 1, thid.length);
				var num1 = $('#quantity_' + index).val();
				var num2 = $('#unitPrice_' + index).val();
				if(patrnNumber.exec(num1) && patrnNumber.exec(num2)){
					var num3 = (parseFloat(num1) * parseFloat(num2)).toFixed(2);
					$('#money_' + index).val(num3);
					$('#unitPrice_' + index).parent().parent().next().text(num3).css('padding-left', '2px');
				}else{
					$('#money_' + index).val('');
					$('#unitPrice_' + index).parent().parent().next().text(' ');
				}
			})
		}else{
			copyTr.find("input[id*=quotaReward],input[id*=ratioReward]").blur(function(){
				countReward($(this).attr('id'));
			})
			copyTr.find("select[id*=currency]").change(function(){
				countReward($(this).attr('id'));
			})
		}
		table.find("tr:last").after(copyTr);
		if(table.find('tr').size() % 2 == 0){
			copyTr.addClass('tr1');
		}
		feeOpFlag = 1;
	}
	
	function countReward(thid){
		var index = thid.substring(thid.indexOf('_') + 1, thid.length);
		var currency = $('#currency_' + index).val();
		if(currency != 0){
			var num1 = $('#quotaReward_' + index).val();
			var num2 = $('#ratioReward_' + index).val();
			var suffix;
			if(num2 != ''){
				if(num2.charAt(num2.length - 1) != '%'){
					num2 += '%';
					$('#ratioReward_' + index).val(num2);
				}
				suffix = num2.substring(num2.length - 1, num2.length);
				num2 = num2.substring(0, num2.length - 1);
			}
			var num3 = 0;
			if(patrnNumber.exec(num1)){
				num3 += parseFloat(num1);
			}
			if(patrnNumber.exec(num2) && parseFloat(num2) > 0 && parseFloat(num2) < 100 && suffix == '%'){
				var receive = 0;
				if($('#span_count_2').text() != ''){
					receive = parseFloat($('#span_count_2').text());
				}
				var pay = 0;
				if($('#span_count_4').text() != ''){
					pay = parseFloat($('#span_count_4').text());
				}
				if(receive > pay){
					var rate1 = currencyArrs[$('#maincurrency').val()];
					var rate2 = currencyArrs[currency];
					num3 += ((receive - pay) * rate1 / rate2) * (parseFloat(num2) / 100);
				}
			}
			num3 = num3.toFixed(2);
			if(num3 == 0){
				num3 = ' ';
			}
			$('#ratioReward_' + index).parent().parent().next().text(num3).css('padding-left', '2px');
		}else{
			$('#ratioReward_' + index).parent().parent().next().text(' ').css('padding-left', '2px');
		}
	}
	
	function selectItems(){
		if(feeOpFlag == 1){
			alert('请先完成正在操作中的费用！');
			return;
		}
		openPopDiv('fee_items_div','selectItems?workId=' + workId,'150');
	}
	
	function confirmItems(){
		for(i=0; i<preError.length; i++){
			normalCss(preError[i]);
		}
		var errormsg = checkWorkItem($('#workItemId0').parents('tr'));
		if(errormsg == ''){
			var besaveObj = $('#workItemId0').parents('table');
			besaveObj.wrap('<form id="feeFormTemp_"></form>');
			var params = besaveObj.parent().serialize();
			besaveObj.unwrap();
			$.post("cts/saveWorkItemByFee", params, function(data){
				if(data != ''){
					var fees = $('#fees').val();
					var index = $('#index').val();
					var tabindex = $('#tabindex').val();
					$('#fees_' + index).attr('srcValue', fees);
					saveFees(index, tabindex);
				}else{
					alert('保存失败，请稍候再试！');
				}
			});
		}else{
			alert(errormsg)
			return;
		}
	    closePopDiv('fee_items_div');
	}
	
	var preErrorId = [];
	function saveFees(index, tabindex){
		var ispass = true;
		var errorId = [];
		
		var employee1Id = $('#employee1Id_' + index).val();
		if(employee1Id == ''){
			errorId[errorId.length] = "employee1_";
		}
		var currency = $('#currency_' + index).val();
		if(currency == 0){
			errorId[errorId.length] = "currency_";
		}
		if(tabindex == 1 || tabindex == 2){
			var fees = $('#fees_' + index).val();
			if(fees == 0){
				errorId[errorId.length] = "fees_";
			}
			var quantity = $('#quantity_' + index).val();
			if(!patrnNumber.exec(quantity)){
				errorId[errorId.length] = "quantity_";
			}
			var unitPrice = $('#unitPrice_' + index).val();
			if(!patrnNumber.exec(unitPrice)){
				errorId[errorId.length] = "unitPrice_";
			}
		}else if(tabindex == 3){
			var quotaReward = $('#quotaReward_' + index).val();
			var ratioReward = $('#ratioReward_' + index).val();
			if(quotaReward != '' && !patrnNumber.exec(quotaReward)){
				errorId[errorId.length] = "quotaReward_";
			}
			if(ratioReward != '' && (!patrnNumber.exec(ratioReward.substring(0, ratioReward.length - 1)) 
				|| parseFloat(ratioReward.substring(0, ratioReward.length - 1)) <= 0 || parseFloat(ratioReward.substring(0, ratioReward.length - 1)) >= 100 
				|| ratioReward.substring(ratioReward.length - 1, ratioReward.length) != '%')){
				errorId[errorId.length] = "ratioReward_";
			}
			if(quotaReward == '' && ratioReward == ''){
				errorId[errorId.length] = "quotaReward_";
				errorId[errorId.length] = "ratioReward_";
			}
		}
		
		for(var i=0; i<preErrorId.length; i++){
			normalCss(preErrorId[i] + index);
		}
		for(var i=0; i<errorId.length; i++){
			ispass = false;
			errorCss(errorId[i] + index);
		}
		preErrorId = errorId;
		
		if(!ispass){
			alert('缺少必填项或输入的值不正确！');
			return;
		}
		var isDeleteItem = '';
		if(tabindex == 2){
			var srcValue = $('#fees_' + index).attr('srcValue');
			var nowValue = $('#fees_' + index).val();
			if(srcValue != nowValue && srcValue != ''){
				var srcHasItem = $('#fees_' + index).attr('srcHasItem');
				var hasItem = $('#fees_' + index + ' option:selected').attr('hasItem');
				if(srcHasItem != '' || hasItem != ''){
					var flag = <s:property value="work.pointORG != null"/>;
					if(flag){
						if(confirm('修改该应付款的费用名称，必须同步修改对应的作业项目，确定要修改吗？')){
							if(srcHasItem == '1' && hasItem == ''){
								isDeleteItem += '&srcHasItem=' + srcHasItem + '&hasItem=' + hasItem;
							}else{
								openPopDiv('fee_items_div','workStep4?workFeeId=' + $('#workFeeId_' + index).val() + '&fees=' + nowValue + '&employee1Id=' + employee1Id + '&index=' + index + '&tabindex=' + tabindex, '150');
								return;
							}
						}else{
							return;
						}
					}else{
						isDeleteItem += '&srcHasItem=' + srcHasItem + '&hasItem=' + hasItem;
					}
				}
			}
		}
		var besaveObj = $('#feeTr_' + index);
		besaveObj.wrap('<form id="feeFormTemp_'+index+'"></form>');
		var params = besaveObj.parent().serialize();
		besaveObj.unwrap();
		$.post("cts/workStep5.action?save=true&op=save&workId=" + workId + '&index=' + index + isDeleteItem, params, function(data){
			if(data != ''){
				$('#workFeeId_' + index).val(data);
				toViewFeesStyle(tabindex, index);
				feeOpFlag = 0;
				countFees(tabindex);
				if(tabindex == 2){
					$('#fees_' + index).attr('srcValue', $('#fees_' + index).val());
					$('#fees_' + index).attr('srcHasItem', $('#fees_' + index + ' option:selected').attr('hasItem'));
				}
			}else{
				alert('操作失败，请稍候再试！');
			}
	    });
	}
	
	//检查逻辑错误
	function fillLocaleText(id, type){
		if(id.indexOf('employee') != -1){
			var index = id.substring(id.indexOf('_') + 1, id.length);
			var id1 = $('#employee1Id_' + index).val();
			var id2 = $('#employee2Id_' + index).val();
			if(id1 != '' && id1 == id2){
				alert('付款方不能和代付方一样！');
				if(id.indexOf('employee1Id_') != -1){
					$('#employee1Id_' + index).val('');
					$('#employee1_' + index).val('');
				}else{
					$('#employee2Id_' + index).val('');
					$('#employee2_' + index).val('');
				}
			}
		}
	}
	
	//删除费用
	function deleteFees(index, tabindex){
		if(feeOpFlag == 1 && index != feeSum){
			alert('请先完成正在操作中的费用！');
			return;
		}
		var workFeeId = $('#workFeeId_' + index).val();
		var text = '确定要删除该费用吗？';
		if(tabindex == 2){
			text = '删除该应付款将会删除对应的作业项目，你确定要删除吗？';
		}else if(tabindex == 3){
			text = '确定要删除该奖励吗？';
		}
		if(workFeeId != ''){
			if(confirm(text)){
				$.post("cts/workStep5.action?save=true&op=delete&workFeeId=" + workFeeId, null, function(data){
					if(data == 1){
						$('#feeTr_' + index).remove();
						countFees(tabindex);
					}else{
						alert('操作失败，请稍候再试！');
					}
			    });
			}
		}else{
			$('#feeTr_' + index).remove();
			feeOpFlag = 0;
		}
	}
	
	function toEditFeesStyle(index, tabindex){
		if(feeOpFlag == 1){
			alert('请先完成正在操作中的费用！');
			return;
		}
		var obj = $('#feeTr_' + index);
		obj.find('td').each(function(){
			$(this).find('span:eq(0)').hide();
			$(this).find('span:eq(1)').show();
		})
		if(tabindex == 1 || tabindex == 2){
			obj.find("input[id*=quantity],input[id*=unitPrice]").blur(function(){
				var thid = $(this).attr('id');
				var index = thid.substring(thid.indexOf('_') + 1, thid.length);
				var num1 = $('#quantity_' + index).val();
				var num2 = $('#unitPrice_' + index).val();
				if(patrnNumber.exec(num1) && patrnNumber.exec(num2)){
					var num3 = (parseFloat(num1) * parseFloat(num2)).toFixed(2);
					$('#money_' + index).val(num3);
					$('#unitPrice_' + index).parent().parent().next().text(num3).css('padding-left', '2px');
				}else{
					$('#money_' + index).val('');
					$('#unitPrice_' + index).parent().parent().next().text(' ');
				}
			})
		}else{
			obj.find("input[id*=quotaReward],input[id*=ratioReward]").blur(function(){
				countReward($(this).attr('id'));
			})
			obj.find("select[id*=currency]").change(function(){
				countReward($(this).attr('id'));
			})
		}
		feeOpFlag = 1;
	}
	
	function toViewFeesStyle(tabindex, index){
		var obj = $('#feeTr_' + index).find('td');
		obj.each(function(){
			$(this).find('span:eq(0)').show();
			$(this).find('span:eq(1)').hide();
		})
		if(tabindex == 1 || tabindex == 2){
			obj.not(':last').css('padding', '2px');
			obj.eq(0).find('span:eq(0)').text(obj.eq(0).find('span:eq(1)').find('input[id*=employee1_]').val());
			obj.eq(1).find('span:eq(0)').text(obj.eq(1).find('span:eq(1)').find('select option:selected').text());
			obj.eq(2).find('span:eq(0)').text(obj.eq(2).find('span:eq(1)').find('select option:selected').text());
			
			obj.eq(3).find('span:eq(0)').text(obj.eq(3).find('span:eq(1)').find('input[id*=quantity_]').val());
			obj.eq(4).find('span:eq(0)').text(obj.eq(4).find('span:eq(1)').find('input[id*=unitPrice_]').val());
			
			var employee2Id = obj.eq(6).find('span:eq(1)').find('input[id*=employee2Id_]').val();
			if(!employee2Id || employee2Id == ''){
				obj.eq(6).find('span:eq(1)').find('input[id*=employee2_]').val('');
			}
			obj.eq(6).find('span:eq(0)').text(obj.eq(6).find('span:eq(1)').find('input[id*=employee2_]').val() + ' ');
			obj.eq(8).find('span:eq(0)').find('div').text(obj.eq(8).find('span:eq(1)').find('input[id*=remark_]').val() + ' ');
			obj.eq(8).attr('title', obj.eq(8).find('span:eq(0)').find('div').text());
		}else{
			obj.not(':last').css('padding', '2px');
			obj.eq(0).find('span:eq(0)').text(obj.eq(0).find('span:eq(1)').find('input[id*=employee1_]').val());
			obj.eq(1).find('span:eq(0)').text(obj.eq(1).find('span:eq(1)').find('select option:selected').text());
			
			obj.eq(2).find('span:eq(0)').text(obj.eq(2).find('span:eq(1)').find('input[id*=quotaReward_]').val() + ' ');
			obj.eq(3).find('span:eq(0)').text(obj.eq(3).find('span:eq(1)').find('input[id*=ratioReward_]').val() + ' ');
			
			obj.eq(6).find('span:eq(0)').find('div').text(obj.eq(6).find('span:eq(1)').find('input[id*=remark_]').val() + ' ');
			obj.eq(6).attr('title', obj.eq(6).find('span:eq(0)').find('div').text());
		}
	}
	
	function countFees(tabindex){
		var currency = $('#maincurrency option:selected');
		$('#span_count_1,#span_count_3,#span_count_5').text(currency.text());
		if(tabindex == 1){
			var rate1 = currencyArrs[currency.val()];
			var totalMoney = 0;
			$('#feeTable1 tr:visible:gt(0)').each(function(){
				var _money = $(this).find('input[id*=money_]').val();
				var _currency = $(this).find('select[id*=currency_] option:selected').val();
				var rate2 = currencyArrs[_currency];
				if(_money && _money != '' && _currency && _currency != '' && rate2 && rate2 != ''){
					totalMoney += _money * rate2 / rate1;
				}
			})
			$('#span_count_2').text(totalMoney.toFixed(2));
			countFees(3);
		}else if(tabindex == 2){
			var totalMoney = 0;
			var rate1 = currencyArrs[currency.val()];
			$('#feeTable2 tr:visible:gt(0)').each(function(){
				var _money = $(this).find('input[id*=money_]').val();
				var _currency = $(this).find('select[id*=currency_] option:selected').val();
				var rate2 = currencyArrs[_currency];
				if(_money && _money != '' && _currency && _currency != '' && rate2 && rate2 != ''){
					totalMoney += _money * rate2 / rate1;
				}
			})
			$('#span_count_4').text(totalMoney.toFixed(2));
			countFees(3);
		}else if(tabindex == 3){
			if(auth2 == 1){
				var rate1 = currencyArrs[currency.val()];
				var totalMoney = 0;
				$('#feeTable3 tr:visible:gt(0)').each(function(){
					var _quotaReward = $(this).find('input[id*=quotaReward_]').val();
					var _ratioReward = $(this).find('input[id*=ratioReward_]').val();
					var _currency = $(this).find('select[id*=currency_] option:selected').val();
					var rate2 = currencyArrs[_currency];
					if(_currency && rate2){
						var rowCount = 0;
						if(_quotaReward && $.trim(_quotaReward) != ''){
							_quotaReward = $.trim(_quotaReward);
							rowCount += parseFloat(_quotaReward);
						}
						if(_ratioReward && $.trim(_ratioReward) != ''){
							_ratioReward = $.trim(_ratioReward);
							var ratioReward = _ratioReward.substring(0, _ratioReward.length - 1);
							var receive = 0;
							if($('#span_count_2').text() != ''){
								receive = parseFloat($('#span_count_2').text());
							}
							var pay = 0;
							if($('#span_count_4').text() != ''){
								pay = parseFloat($('#span_count_4').text());
							}
							if(receive > pay){
								rowCount += ((receive - pay) * rate1 / rate2) * (parseFloat(ratioReward) / 100);
							}
						}
						$(this).find('input[id*=ratioReward_]').parent().parent().next().text(rowCount.toFixed(2));
						totalMoney += rowCount * rate2 / rate1;
					}
				})
				$('#span_count_6').text(totalMoney.toFixed(2));
			}
		}
	}
	
</script>













